﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
using System.IO;
using Media.Core.Data;
using Media.Core.Logic;
using Media.Core.Models.Tv;
using Media.Core.Helpers.Main;
using System.Web.Security;
using Media.Core.Models;
using Media.Web.Controllers.Base;

namespace Media.Web.Controllers
{
    public class TvController : BaseController
    {
        public ActionResult Index()
        {
            return View(TvEngine.AllTvShows());
        }

        public ActionResult YourShows()
        {
            try
            {
                return View(TvEngine.UserTvShows(Membership.GetUser().ProviderUserKey.ToString()));
            }
            // User Not Logged In.
            catch
            {
                return RedirectToAction("LogOn", "Account");
            }
        }

        public ActionResult Search()
        {

            var objDir = new DirectoryInfo(GetDirectory.Location("Tv Shows")); // gets the tv show dir

            var dirInfos = objDir.GetDirectories("*.*"); // sets the dir to select all folders in dir

            var add = TvEngine.Search(dirInfos, Membership.GetUser().ProviderUserKey.ToString());

            var submission = new SubmissionCheck
            {
                Check = 1,
                Message = add
            };

            return Json(submission, JsonRequestBehavior.AllowGet);
            
        }

        public ActionResult Details(int id)
        {
            return View(TvEngine.TvShowDetails(id));
        }

        public ActionResult Season(int tvId, int seasonId)
        {
            return View(TvEngine.SeasonDetails(tvId, seasonId));
        }

        public ActionResult Latest()
        {
            return View(TvEngine.GetComingEpisodes());
        }

        public ActionResult Table()
        {
            return View(TvEngine.AllTvShows());
        }
    }
}
